/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:54 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class ChungchiDAL : SqlProvider<ChungchiEntity>
    {
        static ChungchiDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                ChungchiEntity entity = new ChungchiEntity();
				entity.PK_iChungchiID = Int16.Parse("0"+dr["PK_iChungchiID"].ToString());
				entity.sTenchungchi = dr["sTenchungchi"].ToString();
				entity.sKyhieu = dr["sKyhieu"].ToString();
				entity.bLogo = Byte.Parse("0"+dr["bLogo"].ToString());
				entity.sTendonvicap = dr["sTendonvicap"].ToString();
				entity.iThangdiem = Int16.Parse("0"+dr["iThangdiem"].ToString());
				entity.iThoihan = Byte.Parse("0"+dr["iThoihan"].ToString());
                return entity;
            };
        }
        public static ChungchiEntity GetOne(Int16 PK_iChungchiID)
        {
            string cmdName = "spChungchi_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iChungchiID", PK_iChungchiID);
            ChungchiEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<ChungchiEntity> GetAll()
        {
            string cmdName = "spChungchi_Get";
            return GetList(cmdName);
        }
        
        public static int Add(ChungchiEntity entity)
        {
            string cmdName = "spChungchi_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(ChungchiEntity entity)
        {
            string cmdName = "spChungchi_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 PK_iChungchiID)
        {
            string cmdName = "spChungchi_Delete";
            SqlParameter p = new SqlParameter("@PK_iChungchiID", PK_iChungchiID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(ChungchiEntity entity)
        {
            SqlParameter[] p = new SqlParameter[7];
			p[0] = new SqlParameter("@PK_iChungchiID", entity.PK_iChungchiID);
			p[1] = new SqlParameter("@sTenchungchi", entity.sTenchungchi);
			p[2] = new SqlParameter("@sKyhieu", entity.sKyhieu);
			p[3] = new SqlParameter("@bLogo", entity.bLogo);
			p[4] = new SqlParameter("@sTendonvicap", entity.sTendonvicap);
			p[5] = new SqlParameter("@iThangdiem", entity.iThangdiem);
			p[6] = new SqlParameter("@iThoihan", entity.iThoihan);
            return p;
        }
        #endregion
       
    }
}